package com.shop.controller;

import com.github.pagehelper.PageInfo;
import com.shop.base.BaseController;
import com.shop.entity.Order;
import com.shop.result.ResultVO;
import com.shop.service.OrderService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequiredArgsConstructor
@RequestMapping("/order")
public class OrderController extends BaseController {
    private final OrderService orderService;
    @GetMapping("/listOrder")
    public ResultVO<PageInfo<Order>> listOrder(@RequestParam("pageNum") Integer page, @RequestParam("pageSize") Integer limit) {
        PageInfo<Order> orders = orderService.listOrder(page, limit);
        return success(orders);
    }

    @GetMapping("/getOrderById")
    public ResultVO<Order> getOrderById(@RequestParam("id") int id) {
        Order order = orderService.getOrderById(id);
        return success(order);
    }

    @GetMapping("/getOrderByOrderId")
    public ResultVO<Order> getOrderByOrderId(@RequestParam("orderId") String orderId) {
        Order order = orderService.getOrderByOrderId(orderId);
        return success(order);
    }


    @PostMapping("/addOrder")
    public ResultVO<Object> addOrder(@RequestBody Order order) {
        orderService.addOrder(order);
        return success("添加成功");
    }

    @PostMapping("/updateOrder")
    public ResultVO<Object> updateOrder(@RequestParam("id") Integer id, @RequestParam("status") String status) {
        orderService.updateOrder(id, status);
        return success("修改成功");
    }

    @PostMapping("/deleteOrder")
    public ResultVO<Object> deleteOrder(@RequestParam("id") Integer id) {
        orderService.deleteOrder(id);
        return success("删除成功");
    }

    @GetMapping("/countOrder")
    public ResultVO<Object> countOrder() {
        return success(orderService.getTotal());
    }

    @GetMapping("/countOrderMoney")
    public ResultVO<Object> countOrderMoney() {
        return success(orderService.countOrderMoney());
    }

    @GetMapping("/getTotalStatus")
    public ResultVO<PageInfo<Order>> getTotalStatus(@RequestParam("status") String status, @RequestParam("pageNum") Integer page, @RequestParam("pageSize") Integer limit) {
        PageInfo<Order> orders = orderService.getTotalStatus(status, page, limit);
        return success(orders);
    }

    @GetMapping("/getOrderByUserId")
    public ResultVO<List<Order>> getOrderByUserId(@RequestParam("id") Integer id) {
        List<Order> orders = orderService.getOrderByUserId(id);
        return success(orders);
    }

    @GetMapping("/getOrderByIdAndStatus")
    public ResultVO<PageInfo<Order>> getOrderByIdAndStatus(@RequestParam("id") Integer id, @RequestParam("status") String status, @RequestParam("pageNum") Integer page, @RequestParam("pageSize") Integer limit) {
        PageInfo<Order> orders = orderService.getOrderByIdAndStatus(id, status, page, limit);
        return success(orders);
    }
}
